package com.jumi.microservice.api;

import com.jumi.microservice.jwt.annon.IgnoreUrlsAnnon;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.utils.ResultGenerator;
import com.jumi.microservice.constant.ExceptionEnum;
import com.jumi.microservice.domain.RotationChart;
import com.jumi.microservice.domain.vo.RotationChartVO;
import com.jumi.microservice.service.RotationChartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/RotationChartApi")
@Api(tags = "C-轮播图相关接口")
public class RotationChartApiController {
    @Autowired
    private RotationChartService rotationChartService;

    @ApiOperation(value = "获取部门表分页列表数据", notes = "获取部门表分页列表数据")
    @GetMapping("/RotationChartList")
    @IgnoreUrlsAnnon("/RotationChartList")
    public ResponseResult<List<RotationChartVO>> list() {
        List<RotationChartVO> vos = rotationChartService.selectRotationChartList();
        return ResultGenerator.genSuccessResult(vos);
    }

    /**
     * 部门DO对象转换 do->vo
     *
     * @param rotationCharts 部门do集合
     * @return 部门VO集合
     */
    private List<RotationChartVO> pos2Vos(List<RotationChart> rotationCharts) {
        List<RotationChartVO> pos = rotationCharts.stream().map(p -> {
            RotationChartVO vo = null;
            try {
                vo = p.clone(RotationChartVO.class);
            } catch (Exception e) {
                ExceptionEnum.FAIL_CHANGE.newException();
            }
            return vo;
        }).collect(Collectors.toList());
        return pos;
    }
}
